<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>生成器</title>
</head>
<body>
    <script>
        /* 
            当我们调用的时候，不会像普通函数一样立即执行
            有 n 个yield，就需要执行 n+1 个next()
        
         */
        function* gen(){
            console.log('调用开始');
            yield '状态1'
            console.log("调用 1");
            yield '状态2'
            console.log("调用 2");
            yield '状态3'
            console.log("调用 3");
            yield '状态4'
            console.log('结束');
        }
        let it = gen() 
        it.next()
        it.next()
        it.next()
        it.next()
        it.next()
    </script>
</body>
</html>